from PyQt5.QtWidgets import (
    QDialogButtonBox,
    QDateTimeEdit,
    QDialog,
    QComboBox,
    QTableView,
    QAbstractItemView,
    QHeaderView,
    QTableWidget,
    QTableWidgetItem,
    QMessageBox,
    QListWidget,
    QListWidgetItem,
    QStatusBar,
    QMenuBar,
    QMenu,
    QAction,
    QLineEdit,
    QStyle,
    QFormLayout,
    QVBoxLayout,
    QWidget,
    QApplication,
    QHBoxLayout,
    QPushButton,
    QMainWindow,
    QGridLayout,
    QLabel,
)
from PyQt5.QtGui import (
    QIcon,
    QPixmap,
    QStandardItem,
    QStandardItemModel,
    QCursor,
    QFont,
    QBrush,
    QColor,
    QPainter,
    QMouseEvent,
    QImage,
    QTransform,
)
from PyQt5.QtCore import (
    QStringListModel,
    QAbstractListModel,
    QModelIndex,
    QSize,
    Qt,
    QObject,
    pyqtSignal,
    QTimer,
    QEvent,
    QDateTime,
    QDate,
)

import sys


class Win(QWidget):
    def __init__(self, parent=None):
        super().__init__()
        self.resize(400, 400)

        self.label = QLabel("这里显示信息", self)
        self.btn = QPushButton("Open", self)
        self.btn1 = QPushButton("Reset", self)
        self.btn.move(50, 50)
        self.btn1.move(150, 50)
        self.btn.setMinimumWidth(120)
        self.btn.clicked.connect(self.openDialog)  # 按钮绑定槽函数，用于打开子窗口
        self.btn1.clicked.connect(
            lambda: self.label.clear()
        )  # 按钮绑定槽函数，用于打开子窗口

    # 打开Dialog
    def openDialog(self):
        dialog = Child_Dialog(self)
        dialog.signal1.connect(self.slot_func)
        # 连接【子窗口内置消息和主窗口的槽函数】
        dialog.show()  # 非阻塞
        # dialog.exec_()        # 阻塞

    def slot_func(self, message):
        self.label.setText(message)


# 弹出框对象
class Child_Dialog(QDialog):
    # 自定义消息

    signal1 = pyqtSignal(str)

    def __init__(self, parent=None):
        super(Child_Dialog, self).__init__(parent)
        layout = QVBoxLayout(self)
        self.label = QLabel(self)
        self.button = QPushButton("send")
        self.button.clicked.connect(self.func1)
        layout.addWidget(self.label)
        layout.addWidget(self.button)
        self.setLayout(layout)

    def func1(self):
        self.signal1.emit("hello")


if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = Win()
    win.show()
    sys.exit(app.exec_())
